package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.common.annotion.log.BussinessLog;
import com.stylefeng.guns.common.constant.Dict;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.persistence.dao.JoinNodeMapper;
import com.stylefeng.guns.common.persistence.model.JoinNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * 商家入驻控制器
 *
 * @author cq
 * @Date 2018-08-09 16:32:21
 */
@Controller
@RequestMapping("/joinNode")
public class JoinNodeController extends BaseController {

    private String PREFIX = "/system/joinNode/";

    @Autowired
    private JoinNodeMapper joinNodeMapper;
    /**
     * 跳转到节点首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "joinNode.html";
    }

    /**
     * 跳转到添加节点
     */
    @RequestMapping("/joinNode_add")
    public String joinAdd() {
        return PREFIX + "joinNode_add.html";
    }

    /**
     * 跳转到修改节点
     */
    @RequestMapping("/joinNode_update/{joinId}")
    public String joinUpdate(@PathVariable Integer joinId, Model model) {
        JoinNode old=this.joinNodeMapper.selectById(joinId);
        model.addAttribute("join",old);
        return PREFIX + "joinNode_edit.html";
    }

    /**
     * 获取节点列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<JoinNode> joinNodes = joinNodeMapper.selectList(null);
        return joinNodes;
        }


    /**
     * 新增节点
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(JoinNode joinNode) {
        if(joinNode !=null){
            joinNode.setCreateDate(new Date());
        }
        Integer insert = joinNodeMapper.insert(joinNode);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除节点
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除节点",key = "joinId",dict = Dict.DeleteDict)
        public Object delete(@RequestParam Integer joinId) {
        this.joinNodeMapper.deleteById(joinId);
        return SUCCESS_TIP;
    }

    /**
     * 修改节点
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @BussinessLog(value = "修改节点",key = "joinId",dict = Dict.DictMap)
    public Object up(JoinNode joinNode) {
        Integer update=joinNodeMapper.updateById(joinNode);
        return super.SUCCESS_TIP;
    }
    /**
     * 节点详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
